﻿' LibWowAPI
' by Ronald M. Clifford (roncli@roncli.com)
'
' This source code is released under the GNU Library General Public License (LGPL) Version 2.1.

Imports System
Imports System.Globalization
Imports Newtonsoft.Json

Namespace roncliProductions.LibWowAPI.Quest

    ''' <summary>
    ''' A class that retrieves quest information from the Blizzard WoW API.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class QuestLookup
        Inherits WowAPIData

        Private qlQuest As New Schema.quest

#Region "WowAPIData Overrides"

#Region "Public Properties"

        ''' <summary>
        ''' The options for looking up a quest.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Options As New QuestLookupOptions

        ''' <summary>
        ''' The length of time the data should be cached for, defaulting to 30 days for quest information.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overrides Property CacheLength As New TimeSpan(30, 0, 0, 0)

#End Region

#Region "Protected Properties"

        Protected Overrides ReadOnly Property CacheKey As String
            Get
                Return String.Format(CultureInfo.InvariantCulture, "LibWowAPI.Quest.{0}", Options.QuestID)
            End Get
        End Property

        Protected Overrides ReadOnly Property URI As Uri
            Get
                Return New Uri(String.Format(CultureInfo.InvariantCulture, "/api/wow/quest/{0}", Options.QuestID), UriKind.Relative)
            End Get
        End Property

#End Region

#End Region

#Region "Properties"

        Private qQuest As Quest
        ''' <summary>
        ''' The quest returned from the Blizzard WoW API.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Quest As Quest
            Get
                Return qQuest
            End Get
        End Property

#End Region

#Region "Methods"

#Region "Constructors"

        ''' <summary>
        ''' A default constructor to retrieve quest information from the Blizzard WoW API.
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
        End Sub

        ''' <summary>
        ''' A constructor to retrieve quest information for a quest from the Blizzard WoW API.
        ''' </summary>
        ''' <param name="intQuestID"></param>
        ''' <remarks></remarks>
        Public Sub New(intQuestID As Integer)
            Options.QuestID = intQuestID
            Load()
        End Sub

#End Region

        ''' <summary>
        ''' Loads the quest.
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub Load()
            MyBase.Retrieve()
            qlQuest = CType(JsonConvert.DeserializeObject(Data, GetType(Schema.quest)), Schema.quest)
            qQuest = New Quest(
                qlQuest.id,
                qlQuest.title,
                qlQuest.reqLevel,
                qlQuest.suggestedPartyMembers,
                qlQuest.category,
                qlQuest.level
                )
        End Sub

#End Region

    End Class

End Namespace
